package com.lovo.sys.controller;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lovo.commom.util.ConvertBeanUtil;
import com.lovo.sys.bean.ProductBean;
import com.lovo.sys.bean.ProductInfoBean;
import com.lovo.sys.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("product")
public class ProductController {
    @Autowired
    private IProductService productService;

    @GetMapping("findByProductStatus")
    public String findByProductStatus() {
        List<ProductBean> productBeanList = productService.findByProductStatus();
        String json = JSON.toJSONString(productBeanList);
        return json;
    }

    @GetMapping("findListedProduct")
    public IPage<ProductBean> findListedProduct(int pageNO, String productType, int status) {
        return productService.findListedProduct(pageNO, productType, status);
    }

    @RequestMapping("updateStatusToDown/{productName}")
    public String updateStatusToDown(@PathVariable("productName") String productName) {
        productService.updateStatusToDown(productName);
        return "ok";
    }

    @GetMapping("findAllProduct/{pageNO}")
    public IPage<ProductBean> findAllProduct(@PathVariable("pageNO") int pageNO) {
        return productService.findAllProduct(pageNO);
    }

    //查看商品明细
    @GetMapping("findByProduct/{productName}")
    public List<ProductInfoBean> findByProduct(@PathVariable("productName") String productName) {
        return productService.findByProduct(productName);
    }

    @GetMapping("findAllType")
    public List<String> findAllType() {
        return productService.findAllType();
    }

    @GetMapping("inKun/{idNum}")
    public String inKun(@PathVariable("idNum") String idNum) {
        productService.inKu(idNum);
        return "ok";
    }

    //远程接口
    @GetMapping("updateProductStatus")
    public boolean updateProductStatus(@RequestParam("productName") String productName, @RequestParam("status") int status) {
        if (productService.updateProductStatus(productName, status)) {
            return true;
        } else {
            return false;
        }
    }

    @GetMapping("updateProductInfoPrice")
    public boolean updateProductInfoPrice(@RequestParam("obj") String obj) {
        if (productService.updateProductInfoPrice(obj)) {
            return true;
        }
        return false;
    }
    @GetMapping("outKu")
    public boolean outKu(@RequestParam("productName") String productName,@RequestParam("specs") String specs,@RequestParam("num") int num){
        productService.outKu(productName, specs, num);
        return true;
    }

    @GetMapping("addSnowId")
    public boolean addSnowId(@RequestParam("productName") String productName,@RequestParam("snowId") String snowId){
        productService.addSnowId(productName, snowId);
        return true;
    }

}
